﻿// Revision section
// Last update:		LK 16/04/2012
// Changes tracking
// *******************************************************************
// By	Date		Project		Description
// *******************************************************************
// LK 	16/04/2012	<<D1120>>	Purchase calculation should take into account items not delivered when Purchase Order 
// *******************************************************************
namespace EasyPO
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Reflection;

    /*! Purchase class */
	public class Purchase : IPurchase
    {
        # region Constructors

        public Purchase()
        {
        }

        public Purchase(
            string id,
            string description,
            string reasonfororder,
            string nomcode,
            string nomdesc,
            double unitprice,
            int quantity,
            string suppliercode,
            string notes = null,
            string deliverynotes = null,
            DateTime dateposted = new DateTime(),
            DateTime datetransaction = new DateTime(),
            string packsize = "",
            string username = "",
            int quantityReceived = 0,
            string potranline = null,
            double invoicePrice = 0,
            int po_id = 0
            )
        {
            Id = id;
            Description = description;
            ReasonForOrder = reasonfororder;
            NomCode = nomcode;
            NomDesc = nomdesc;
            UnitPrice = unitprice;
            Quantity = quantity;
            SupplierCode = suppliercode;
            LineValue = (unitprice * quantity);
            Notes = notes;
            DeliveryNotes = deliverynotes;
            DatePosted = dateposted;
            DateTransaction = datetransaction;
            PackSize = packsize;
            Username = username;
            QuantityReceived = quantityReceived;
            PoTranLine_C = potranline;
            InvoicePrice = invoicePrice;
            Po_Id = po_id;
        }

        public Purchase(string id, string description, string whyOrder, string status)
        {
            Id = id;
            Description = description;
            WhyOrder = whyOrder;
            Status = status;

        }

        public Purchase(string id, string description, string whyOrder)
        {
            Id = id;
            Description = description;
            WhyOrder = whyOrder;
        }

        # endregion

        # region Methods

        /*! This method returns total (order price * order qty) for a given purchase order number. */
		/// <summary>
		///  This method returns total (order price * order qty) for a given purchase order number.
		/// </summary>
		public static string GetTotal(string ponumber)
        {
            var lcResult = "";

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT top 1 " +
                        "p.WhyOrder_C + '#' +  convert(varchar(10),p.UserCode_ID) + '#' + convert(varchar(20), sum(p.OrderPrice_N * p.quantityordered_n)) " +
                        "FROM potransactions p " +
                            "WHERE p.ponumber_c = @PoNumber " +
                                "and (p.poallocationorder_N = 0 or p.poallocationorder_N is null) " +
                                "AND deleted = 0 " +
                            "GROUP BY p.WhyOrder_C, p.UserCode_ID", conn);

            try
            {
                // 2. define parameters used in command object
                var param1 = new SqlParameter();
                param1.ParameterName = "@PoNumber";
                param1.Value = ponumber;
                cmd.Parameters.Add(param1);

                conn.Open();

                lcResult = (string)cmd.ExecuteScalar();
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                lcResult = ex.Message.ToString();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public int IsPriceLocked(string ponumber)
        {
            int lnResult;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            // LK 06/02/2012 added [POAllocationOrder_N] filter
            var cmd = new SqlCommand("select isnull(pricelock_n,0) from potransactions (Nolock) " +
                        "where ponumber_c = @PoNumber AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) AND deleted = 0"
                        , conn);

            try
            {
                // define parameters used in command object
                var param1 = new SqlParameter();
                param1.ParameterName = "@PoNumber";
                param1.Value = ponumber;
                cmd.Parameters.Add(param1);

                conn.Open();

                int lockvalue = 0;
                var llResult = int.TryParse(cmd.ExecuteScalar().ToString(), out lockvalue);
                lnResult = lockvalue;
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                lnResult = 0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lnResult;
        }

        public bool FullOrderAllocation(DateTime datereceived, 
            string ponumber, 
            string deliveryReference, 
            out int allocnumber, 
            string fullOrPart = "full",
            int loggedInUserId = 0)
        {
            var llOk = true;
            var liResult = -1;

            var lcSQL = "EXECUTE [dbo].[AllocatePurchaseOrder] @Date, @ponumber, @UserId, @DeliveryReference";
            if (fullOrPart == "part")
                lcSQL = "EXECUTE [dbo].[PartAllocatePurchaseOrder] @Date, @ponumber, @UserId, @DeliveryReference";

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand(lcSQL, conn);
            try
            {
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@Date", Value = datereceived });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@ponumber", Value = ponumber });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@UserId", Value = loggedInUserId });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@DeliveryReference", Value = deliveryReference });
                conn.Open();

                liResult = Convert.ToInt32(cmd.ExecuteScalar());

            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                liResult = 0;
                llOk = false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            allocnumber = liResult;

            return llOk;
        }

        public string GetTemporaryPoNumber()
        {
            int ponumber = 0;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT newidtemp FROM ponewid (NOLOCK) Where type = 'ponum' ", conn);

            try
            {

                conn.Open();

                ponumber = Convert.ToInt32(cmd.ExecuteScalar());

                cmd = new SqlCommand("UPDATE ponewid SET newidtemp = " + (ponumber + 1) + " WHERE type='ponum'", conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                ponumber = 0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            // LK 07/01/2011 <<D0049>> <<D0050>>
            return "prov" + ponumber.ToString().PadLeft(3, '0');
        }

        public string GetPoNumber(string currentPoNumber, int direction, string supplierCode)
        {
            string lcResult;
            string compareChar = "<";
            string ASCorDESC = "DESC";

            SqlDataReader rdr = null;

            if (direction == 0)
            {
                compareChar = "<";
                ASCorDESC = "DESC";
            }

            if (direction == 1)
            {
                compareChar = ">";
                ASCorDESC = "ASC";
            }

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT ponumber_c FROM potransactions (nolock) " +
                        "where ponumber_c in " +
                        "(" +
                           "select top 1 ponumber_C " +
                            "from potransactions (nolock) " +
                            "where ponumber_c " + compareChar + " @PoNumber " +
                            "AND SupplierCode_Id IN ('" + supplierCode.Trim() + "') " +
                            "AND Status Not In ('SEND') " +
                            "AND deleted = 0 " +
                            "AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                            "ORDER BY ponumber_c " + ASCorDESC +
                        ")", conn);

            try
            {
                // 2. define parameters used in command object
                var param1 = new SqlParameter();
                param1.ParameterName = "@PoNumber";
                param1.Value = currentPoNumber;
                cmd.Parameters.Add(param1);

                conn.Open();

                lcResult = (string)cmd.ExecuteScalar();
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                lcResult = null;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public List<string> GetListPoNumber(string status, int deptid = 0, int loggedInUserId = 0)
        {
            string lcWhereDepartment = "";
            if (deptid > 0)
            {
                lcWhereDepartment = " AND DeptCode_Id = " + deptid + " ";
            }

            var lcResult = new List<string>();

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT rtrim(ponumber_c) FROM potransactions (nolock) " +
                        "WHERE status in (" + status + ") " +
                            " AND deleted = 0 AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                        " AND (UserCode_Id = @UserId OR ApprCode_Id = @UserId) " +
                        lcWhereDepartment +
                        " GROUP By ponumber_c ORDER BY Ponumber_C Desc ", conn);

            try
            {
                var param1 = new SqlParameter();
                param1.ParameterName = "@UserId";
                param1.Value = loggedInUserId;
                cmd.Parameters.Add(param1);

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    // get the results of each column
                    lcResult.Add(rdr[0].ToString());
                }
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public List<Purchase> GetListPoNumberObject(string status, int deptid = 0, int loggedInUserId = 0)
        {
            string lcWhereDepartment = "";
            if (deptid > 0)
            {
                lcWhereDepartment = " AND DeptCode_Id = " + deptid + " ";
            }

            var lcDefaultOrder = status.Contains("TEMPL") ? "ORDER By PONumber_C Asc " : "ORDER By PONumber_C Desc ";
            var lcDefaultUserFilter = status.Contains("TEMPL") ? " " : " AND (UserCode_Id = @UserId OR ApprCode_Id = @UserId) ";

            var lcResult = new List<Purchase>();

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("select ponumber_c, " +
                        "suppliercode_id " +
                        ",WhyOrder_C " +
                        ", [Status] " +
                "FROM   potransactions (nolock) " +
                "WHERE  status in (" + status + ") " +
                        lcWhereDepartment +
                        " AND deleted = 0 " +
                        lcDefaultUserFilter +
                "GROUP By ponumber_c, suppliercode_id, WhyOrder_C, status " +
                        lcDefaultOrder, conn);

            //" AND UserCode_Id = " + Globals.loggedInUserId + " " +

            try
            {
                //var param1 = new SqlParameter { ParameterName = "@Status", Value = status };
                //cmd.Parameters.Add(param1);
                var param1 = new SqlParameter();
                param1.ParameterName = "@UserId";
                param1.Value = loggedInUserId;
                cmd.Parameters.Add(param1);

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                if (rdr != null)
                {
                    while (rdr.Read())
                    {
                        // get the results of each column
                        lcResult.Add(new Purchase(rdr[0].ToString(),        //ponumber_c, " +
                                                  rdr[1].ToString(),        //"suppliercode_id " + 
                                                  rdr[2].ToString(),         //",WhyOrder_C
                                                  rdr[3].ToString()             // STATUS
                                         ));
                    }
                }
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        // LK 06/02/2012 Rewrite required // TODO
        public List<Purchase> GetListPoNumbersWithAllocation(string searchTerm = null)
        {
            var lcResult = new List<Purchase>();

            SqlDataReader rdr = null;

            /*
            string id, 
			string description, 
			string reasonfororder, 
			string nomcode, 
			string nomdesc,
			double unitprice, 
			int quantity, 
			string suppliercode, 
			string notes = null, 
			string deliverynotes = null, 
			DateTime dateposted = new DateTime(),
			DateTime datetransaction = new DateTime(), 
			string packsize = "",
			string username = "",
            int quantityReceived = 0
                */
            var lcSearchTerm = "";
            if (!String.IsNullOrEmpty(searchTerm))
            {
                lcSearchTerm = " AND potransactions.PoNumber_C = @SearchTerm";
            }

            var lcSQL = "select potransactions.PoNumber_C, " +
                            "'' as p2, " +
                            "'' as p3, " +
                            "'' as p4, " +
                            "'' as p5, " +
                            "OrderPrice_N, " +
                            "QuantityOrdered_N, " +
                            "'' as p8, " +
                            "'' as p9, " +
                            "'' as p10, " +
                            "isnull(DatePosted_D,GetDate()), " +
                            "isnull(DateTransaction_D,GetDate()), " +
                            "'' as p13, " +
                            "'' as p14, " +
                            "sum(isnull(poallocation.quantityreceived_n,0)), " +
                            "potransactions.PoTranLine_C, " +
                            "avg(isnull(poallocation.invoiceprice_n,0)), " +
                            "potransactions.po_id " +
                        "from potransactions (nolock) " +
                        "left join poallocation (nolock) on poallocation.po_id = potransactions.po_id " +
                        "where potransactions.Status in ('SENT','PARAL') " +
                        lcSearchTerm +
                        " Group by potransactions.PoNumber_C, potransactions.PoTranLine_C, " +
                                "OrderPrice_N, QuantityOrdered_N, DatePosted_D, DateTransaction_D, potransactions.po_id ";

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand(lcSQL, conn);

            //" AND UserCode_Id = " + Globals.loggedInUserId + " " +

            try
            {
                if (!String.IsNullOrEmpty(searchTerm))
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@SearchTerm", Value = searchTerm });
                }

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                if (rdr != null)
                {
                    while (rdr.Read())
                    {
                        // get the results of each column
                        lcResult.Add(new Purchase(rdr[0].ToString(),
                                                  rdr[1].ToString(),
                                                  rdr[2].ToString(),
                                                  rdr[3].ToString(),
                                                  rdr[4].ToString(),
                                                  Convert.ToDouble(rdr[5].ToString()),
                                                  Convert.ToInt32(rdr[6].ToString()),
                                                  rdr[7].ToString(),
                                                  rdr[8].ToString(),
                                                  rdr[9].ToString(),
                                                  Convert.ToDateTime(rdr[10].ToString()),
                                                  Convert.ToDateTime(rdr[11].ToString()),
                                                  rdr[12].ToString(),
                                                  rdr[13].ToString(),
                                                  Convert.ToInt32(rdr[14].ToString()),
                                                  rdr[15].ToString(),
                                                  Convert.ToDouble(rdr[16].ToString()),
                                                  Convert.ToInt32(rdr[17].ToString())
                                         ));
                    }
                }
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public List<string> GetListPoNumberTimer(string status, int deptid = 0)
        {
            string lcWhereDeptid = "";
            if (deptid > 0)
            {
                lcWhereDeptid = " AND DeptCode_Id = " + deptid + " ";
            }

            var lcResult = new List<string>();

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            // LK <<D0078>> 31/01/2011
            var cmd = new SqlCommand("select ponumber_c from potransactions " +
                        "where deleted = 0 AND status in (" + status + ") AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                        lcWhereDeptid +
                        " GROUP By ponumber_c", conn);
            try
            {
                //var param1 = new SqlParameter { ParameterName = "@Status", Value = status };
                //cmd.Parameters.Add(param1);

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    // get the results of each column
                    lcResult.Add(rdr[0].ToString());
                }
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        // LK 06/02/2012 this one does not require change
        public string ConvertPOToTemplate(string currentPoNumber, string templateNumber, 
            bool convertback = false, 
            int loggedInUserId = 0, 
            int loggedInUserDepartmentId = 0)
        {
            string lcResult;

            SqlDataReader rdr = null;

            var lcStatus = "TEMPL";
            if (convertback)
            {
                lcStatus = "OPEN";
            }

            var conn = ConnectionHelper.GetConnection();
            // LK <<D0078>> 31/01/2011 added deleted = 0

            var cmd = new SqlCommand(
                            "INSERT INTO potransactions  " +
                                "(ponumber_c, usercode_id, potranline_c, deptcode_id, suppliercode_id " +
                                ",nomicode_c, whyorder_c, orderprice_n, quantityordered_n, status, " +
                                "Itemdescription_c, dateposted_d, itemcode_id, pricelock_n, packsize_c, deleted) " +
                            "SELECT @TemplateNumber, @UserId, potranline_c, deptcode_id, suppliercode_id, " +
                                "nomicode_c, whyorder_c, orderprice_n, quantityordered_n, '" + lcStatus + "', Itemdescription_c, GetDate(), itemcode_id, 1 " +
                                ",packsize_c, 0 " +
                            "FROM potransactions (Nolock) " +
                            "WHERE deleted = 0 AND PONumber_C = @PoNumber AND deptcode_id = @DeptCodeId " + 
                            " AND NOT EXISTS (SELECT PONumber_C FROM potransactions (Nolock) WHERE PONumber_C = @TemplateNumber) "
                                    , conn);

            try
            {
                // define parameters used in command object
                var param1 = new SqlParameter();
                param1.ParameterName = "@PoNumber";
                param1.Value = currentPoNumber;
                cmd.Parameters.Add(param1);

                var param2 = new SqlParameter();
                param2.ParameterName = "@TemplateNumber";
                param2.Value = templateNumber;
                cmd.Parameters.Add(param2);

                var param3 = new SqlParameter();
                param3.ParameterName = "@UserId";
                param3.Value = loggedInUserId;
                cmd.Parameters.Add(param3);

                cmd.Parameters.Add(new SqlParameter { ParameterName = "@DeptCodeId", Value = loggedInUserDepartmentId });

                conn.Open();

                cmd.ExecuteNonQuery();

                lcResult = "OK";
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                lcResult = ex.Message.ToString();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public static DateTime GetDatePosted(string ponumber)
        {
            DateTime date = Convert.ToDateTime("01/01/2000");
            return date;
        }

        public string AddNewPoNumberRecord(string currentPoNumber, string selectedSupplier)
        {
            string lcResult;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("INSERT INTO potransactions (ponumber_C, suppliercode_id, potranline_c, orderprice_n, quantityordered_n, deleted) " +
                        "VALUES " +
                        "(" +
                           "'" + currentPoNumber + "', " +
                           "'" + selectedSupplier + "', " +
                            "'1', 0, 0, 0 " +
                        ")", conn);

            try
            {
                conn.Open();
                //lcResult = (string)cmd.ExecuteScalar();
                cmd.ExecuteNonQuery();
                lcResult = "OK";
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                lcResult = ex.Message.ToString();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return lcResult;
        }

        public List<Purchase> GetPurchaseOrder(string currentPoNumber)
        {
            var pos = new List<Purchase>();
            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            // LK <<D0080>> 31/01/2011
            var cmd = new SqlCommand("SELECT    isnull(ItemCode_Id,'') as ItemCode_Id, " +
                                                "ponumber_c " +
                                                ",OrderPrice_N as 'Agreed Price' " +
                                                ",QuantityOrdered_N as 'Quantity' " +
                                                ", 20.0 as 'VAT Rate' " +
                                                ", SupplierCode_ID as SupplierCode_Id " +
                                                ", isnull(ItemDescription_C,'') as Description " +
                                                ", isnull(Notes,'') as notes " +
                                                ", DeliveryNotes_C as deliverynotes " +
                                                ", DatePosted_D as [dateposted] " +
                                                ", isnull(DateTransaction_D,GetDate()) as [datetransaction] " +
                                                ", packsize_c as [packsize] " +
                                                ", Username_C as [Username] " +
                                        "FROM potransactions (Nolock) " +
                                        " Left Join pousers (nolock) ON pousers.pouser_id = potransactions.usercode_id " +
                                        "WHERE ponumber_c = @PoNumber AND potransactions.deleted = 0 AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null)"
                        , conn);

            try
            {
                var param1 = new SqlParameter { ParameterName = "@PoNumber", Value = currentPoNumber };
                cmd.Parameters.Add(param1);

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    // get the results of each column

                    /*
                     * 
            string id, 
            string description, 
            string reasonfororder, 
            string nomcode, 
            string nomdesc,
            double unitprice, 
            int quantity, 
            string suppliercode, 
            string notes = null, 
            string deliverynotes = null, 
            DateTime dateposted = new DateTime(),
            DateTime datetransaction = new DateTime(), 
            string packsize = ""
                     * 
                     * 
            0   * ItemCode_Id, " +
            1   "ponumber_c " +
            2   ",OrderPrice_N as 'Agreed Price' " +
            3   ",QuantityOrdered_N as 'Quantity' " +
            4   ", 20.0 as 'VAT Rate' " +
            5    ", SupplierCode_ID as SupplierCode_Id " +
            6   ", ItemDescription_C as Description " +
            7   ", Notes as notes " +
            8   ", DeliveryNotes_C as deliverynotes " +
            9   ", DatePosted_D as [dateposted] " +
            10  ", DateTransaction_D as [datetransaction] " +
            11  ", packsize_c as [packsize] " +
                     * 
                     */

                    pos.Add(new Purchase(
                                        rdr["ItemCode_Id"].ToString(),
                                        rdr[6].ToString(),
                                        string.Empty,
                                        string.Empty,
                                        string.Empty,
                                        Convert.ToDouble(rdr[2]),
                                        Convert.ToInt32(rdr[3]),
                                        rdr[5].ToString(),
                                        rdr[7].ToString(),
                                        rdr[8].ToString(),
                                        (DateTime)rdr[9],
                                        (DateTime)rdr[10],
                                        rdr[11].ToString(),
                                        rdr[12].ToString()
                                        )
                        //,rdr["SupplierCode_Id"]
                                        );
                }
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return pos;
        }

        public Purchase GetPurchase(string currentPoNumber)
        {

            var pos = new Purchase();

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT top 1 ItemCode_Id, " +
                                                "ponumber_c " +
                                                ",OrderPrice_N as 'Agreed Price' " +
                                                ",QuantityOrdered_N as 'Quantity' " +
                                                ", 20.0 as 'VAT Rate' " +
                                                ", SupplierCode_ID as SupplierCode_Id " +
                                                ", ItemDescription_C as Description " +
                                                ", Notes as notes " +
                                                ", DeliveryNotes_C as deliverynotes " +
                                                ", DatePosted_D as [Date Posted] " +
                                        "FROM potransactions (Nolock) " +
                                        "WHERE ponumber_c = @PoNumber AND deleted = 0 AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null)"
                        , conn);

            try
            {
                var param1 = new SqlParameter { ParameterName = "@PoNumber", Value = currentPoNumber.Trim() };
                cmd.Parameters.Add(param1);

                conn.Open();

                // 1.  get an instance of the SqlDataReader
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    // get the results of each column
                    pos = new Purchase(rdr["ItemCode_Id"].ToString(),
                                        rdr[6].ToString(),
                                        string.Empty,
                                        string.Empty,
                                        string.Empty,
                                        Convert.ToDouble(rdr[2]),
                                        Convert.ToInt32(rdr[3]),
                                        rdr[5].ToString(),
                                        rdr[7].ToString(),
                                        rdr[8].ToString(),
                                        Convert.ToDateTime(rdr[9])
                                        );
                }
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return pos;
        }

        public decimal CommitedThisMonthToDate(int loggedInUserDepartmentId)
        {
            string lcTemp = "";

            var conn = ConnectionHelper.GetConnection();

            // LK <<D0078>> 31/01/2011 added deleted=0 to filter deleted (deleted=1) transactions
            var cmd = new SqlCommand("SELECT sum(quantityordered_n * orderprice_n) " +
                                        "FROM potransactions (NOLOCK) " +
                                        "WHERE 1=1 " +
                                        "AND month(isnull(datetransaction_d, dateposted_d)) = " + DateTime.Today.Month + " " +
                                        "AND year(isnull(datetransaction_d, dateposted_d)) = " + DateTime.Today.Year + " " +
                                        "       AND Status In ('APRVD', 'SENT', 'SUSPD', 'HOLD', 'FULL', 'PART', 'POSTD') " +
                                        "       AND DeptCode_Id = @DeptCode " +
                                        "   AND deleted = 0 AND ([POAllocationOrder_N] = 0 OR [POAllocationOrder_N] is null)", conn);

            try
            {
                var param1 = new SqlParameter { ParameterName = "@DeptCode", Value = loggedInUserDepartmentId };
                cmd.Parameters.Add(param1);

                conn.Open();
                lcTemp = cmd.ExecuteScalar().ToString();
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            if (!String.IsNullOrEmpty(lcTemp))
                return Convert.ToDecimal(lcTemp);
            else
                return Convert.ToDecimal(0);
        }

        public decimal ReturnedBudget(int loggedInUserDepartmentId)
        {
            var lcTemp = "";
            var conn = ConnectionHelper.GetConnection();

            var cmd = new SqlCommand("SELECT SUM(QuantityOrdered_N * OrderPrice_N) - SUM(QuantityReceived_N * InvoicePrice_N) " +
                                        "FROM potransactions (NOLOCK) " +
                                        "WHERE 1=1 " +
                                        " AND month(isnull(datetransaction_d, dateposted_d)) = " + DateTime.Today.Month + " " +
                                        " AND year(isnull(datetransaction_d, dateposted_d)) = " + DateTime.Today.Year + " " +
                                        " AND Status In ('APRVD', 'SENT', 'SUSPD', 'HOLD', 'FULL', 'PART', 'POSTD') " +
                                        " AND DeptCode_Id = " + loggedInUserDepartmentId + "" +
                                        " AND deleted = 0 " +
                                        " AND Completed = 1 " +
                                        " AND [POAllocationOrder_N] > 0", conn);

            try
            {
                conn.Open();
                lcTemp = cmd.ExecuteScalar().ToString();
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            if (!String.IsNullOrEmpty(lcTemp))
                return Convert.ToDecimal(lcTemp);
            else
                return Convert.ToDecimal(0);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public decimal CommitedThisMonthToDateExcludingOnHold()
        {
            string lcTemp = "";

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("select sum(quantityordered_n * orderprice_n) " +
                                        "from potransactions (NOLOCK) " +
                                        "where (month(isnull(datetransaction_d, dateposted_d) = month(getdate()) AND year(isnull(datetransaction_d, dateposted_d) = year(getdate())) " +
                                        "AND Status In ('APRVD', 'SENT ', 'SUSPD', 'FULL ', 'PART ', 'POSTD') " +
                                        "AND deleted = 0 AND ([POAllocationOrder_N] = 0 OR [POAllocationOrder_N] is null)"
                        , conn);

            try
            {
                conn.Open();
                lcTemp = cmd.ExecuteScalar().ToString();
            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            if (!String.IsNullOrEmpty(lcTemp))
                return Convert.ToDecimal(lcTemp);
            else
                return Convert.ToDecimal(0);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="currentPoNumber"></param>
        /// <param name="notes"></param>
        /// <param name="whyorder"></param>
        /// <param name="realPoNumber"></param>
        /// <param name="deliverynotes"></param>
        /// <param name="datetransaction"></param>
        /// <param name="keepZeroLines"></param>
        // LK 04/02/2011 <<D0111>> keepZeroLines added
        public void UpdatePOStatus(string status, string currentPoNumber,
                                    string notes = "", string whyorder = "",
                                    string realPoNumber = "", string deliverynotes = "",
                                    string datetransaction = "", bool keepZeroLines = false,
            int loggedInUserId = 0)
        {
            string lcTemp = "";
            var conn = ConnectionHelper.GetConnection();

            var lcChangePoNumber = "";
            var lcApprovedBy = "";
            if (!String.IsNullOrEmpty(status))
            {
                if (status == "SENT")
                {
                    lcChangePoNumber = " , PONumber_C = '" + realPoNumber + "' ";
                    string ldDateApproved = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    lcApprovedBy = " , DatePosted_D = GetDate() ";
                }

                if (status == "APRVD")
                {
                    // LK 02/10/2010 Create correct datetim entry
                    string ldDateApproved = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    lcApprovedBy = " , DateApproved_D = '" + ldDateApproved + "' , ApprCode_Id = @UserId ";
                }
            }

            var lcNotes = "";
            if (!String.IsNullOrEmpty(notes))
                lcNotes = " , Notes = @Notes_C  ";

            var lcDeliveryNotes = "";
            if (!String.IsNullOrEmpty(deliverynotes))
                lcDeliveryNotes = " , DeliveryNotes_C = @DeliveryNotes ";

            var lcWhyOrder = "";
            if (!String.IsNullOrEmpty(whyorder))
                lcWhyOrder = " , WhyOrder_C = @WhyOrder ";

            var lcDataTransaction = "";
            if (!String.IsNullOrEmpty(datetransaction))
            {
                lcDataTransaction = " , DateTransaction_D = '" + Convert.ToDateTime(datetransaction).ToString("yyyy-MM-dd HH:mm:ss") + "' ";
            }

            var cmd = new SqlCommand("UPDATE potransactions " +
                                        "SET Status = @Status " +
                                        lcChangePoNumber +
                                        lcApprovedBy +
                                        lcNotes +
                                        lcWhyOrder +
                                        lcDeliveryNotes +
                                        lcDataTransaction +
                                        " WHERE PONumber_C = @PoNumber"
                        , conn);
            var cmd1 = new SqlCommand("DELETE FROM potransactions " +
                                        "WHERE PONumber_C = @PoNumber AND QuantityOrdered_N = 0"
                        , conn);

            try
            {
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@Status", Value = status });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@PoNumber", Value = currentPoNumber });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@UserId", Value = loggedInUserId });

                if (!String.IsNullOrEmpty(notes))
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@Notes_C", Value = notes });
                }

                if (!String.IsNullOrEmpty(whyorder))
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@WhyOrder", Value = whyorder });
                    //param4.ParameterName = "@WhyOrder";
                    //param4.Value = whyorder;
                    //cmd.Parameters.Add(param4);
                }

                if (!String.IsNullOrEmpty(deliverynotes))
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@DeliveryNotes", Value = deliverynotes });
                }

                var param3 = new SqlParameter();
                param3.ParameterName = "@PoNumber";
                param3.Value = currentPoNumber;
                cmd1.Parameters.Add(param3);

                conn.Open();

                cmd.ExecuteNonQuery();

                // LK 04/02/2011 <<D0111>>
                if (!keepZeroLines)
                {
                    cmd1.ExecuteNonQuery();
                }

            }
            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }

        /// <summary>
        /// Check if the user has got permission to delete this item, must be creator or ADMIN or SUPERVISOR
        /// </summary>
        /// <returns></returns>
        private bool PermissionCheck(string purchasenumber, out string lcMessage, string loggedInUserStatus, int loggedInUserId)
        {
            var llOk = true;
            lcMessage = "";

            if (loggedInUserStatus == "USER")
            {
                int userCount = 0;
                const string lcSQL = "SELECT count(UserCode_Id) " +
                                     " FROM potransactions (NOLOCK) " +
                                     " WHERE PoNumber_C = @PoNumber " +
                                     " AND Status in ('TEMPL') " +
                                     " AND UserCode_ID = @UserId";
                SqlDataReader rdr = null;
                var conn = ConnectionHelper.GetConnection();
                var cmd = new SqlCommand(lcSQL, conn);

                try
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@PoNumber", Value = purchasenumber });
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@UserId", Value = loggedInUserId });
                    conn.Open();
                    //lcResult = (string)cmd.ExecuteScalar();
                    userCount = Convert.ToInt32(cmd.ExecuteScalar());
                }

                catch (Exception ex)
                {
                    EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                    llOk = false;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                }

                if (userCount == 0)
                {
                    llOk = false;
                    lcMessage = "Purchase Order could not be deleted." +
                        "\nOnly creator or users with status of Manager, Supervisor or Admin\nhave the rights to do so.";
                }
            }

            return llOk;
        }

        public static bool DeletePO(string currentPoNumber, int allocationNumber, out string lcError)
        {
            var llOk = true;
            lcError = "";

            SqlDataReader rdr = null;
            var conn = ConnectionHelper.GetConnection();

            if (llOk)
            {
                // LK <<D0078>> 31/01/2011 added deleted = 1
                var lcSQL = "DELETE FROM potransactions " +
                            "WHERE POnumber_C = @CurrentPoNumber " +
                                "AND POAllocationOrder_N = @AllocationNumber " +
                                "AND POAllocationOrder_N > 0 " +
                                "AND Completed = 0";

                var cmd = new SqlCommand(lcSQL, conn);

                try
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@CurrentPoNumber", Value = currentPoNumber });
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@AllocationNumber", Value = allocationNumber });
                    conn.Open();

                    cmd.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                    lcError = ex.Message.ToString();
                    llOk = false;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                }
            }

            return llOk;
        }

        public bool DeletePO(string currentPoNumber, 
            out string cMsg, 
            bool deleteWithPermissionCheck = false, 
            string loggedInUserStatus = null,
            int loggedInUserId = 0)
        {
            var llOk = true;
            var status = "DELET";
            cMsg = "";

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();

            if (deleteWithPermissionCheck)
            {
                llOk = PermissionCheck(currentPoNumber, out cMsg, loggedInUserStatus, loggedInUserId);
                status = "TEMPL";
            }

            if (llOk)
            {
                // LK <<D0078>> 31/01/2011 added deleted = 1
                var lcSQL = "UPDATE potransactions " +
                            "SET status = @Status " +
                                ", deleted = 1 " +
                            "WHERE POnumber_C = @CurrentPoNumber ";

                var cmd = new SqlCommand(lcSQL, conn);

                try
                {
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@CurrentPoNumber", Value = currentPoNumber });
                    cmd.Parameters.Add(new SqlParameter { ParameterName = "@Status", Value = status });

                    conn.Open();

                    //lcResult = (string)cmd.ExecuteScalar();
                    cmd.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                    cMsg = ex.Message.ToString();
                    llOk = false;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                        conn.Close();
                }
            }

            return llOk;
        }

        public void DeletePOWithStatus(string currentStatus)
        {
            string lcResult;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();

            // LK <<D0078>> 31/01/2011 added deleted = 1
            var lcSQL = "UPDATE potransactions " +
                        "SET status = 'DELET' AND deleted = 1 " +
                        "WHERE STATUS = @CurrentStatus AND STATUS NOT IN ('TEMPL') ";

            var cmd = new SqlCommand(lcSQL, conn);

            try
            {
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@CurrentStatus", Value = currentStatus });

                conn.Open();

                //lcResult = (string)cmd.ExecuteScalar();
                cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }

        public bool UpdateDepartment(string ponumber, int newdept)
        {
            var llOk = true;

            //SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("Update PoTransactions " +
                "Set DeptCode_ID = @DeptId " +
                "Where ponumber_c = @PoNumber", conn);

            try
            {
                conn.Open();

                cmd.Parameters.Add(new SqlParameter { ParameterName = "@DeptId", Value = newdept });
                cmd.Parameters.Add(new SqlParameter { ParameterName = "@PoNumber", Value = ponumber });

                cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                llOk = false;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return llOk;
        }

        // LK 07/01/2011 <<D0050>> int => string
        public string GetNewPONumber()
        {
            int ponumber = 0;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand("SELECT newid FROM ponewid (NOLOCK) WHERE type = 'ponum' ", conn);

            try
            {

                conn.Open();

                ponumber = Convert.ToInt32(cmd.ExecuteScalar());

                cmd = new SqlCommand("UPDATE ponewid SET newid = " + (ponumber + 1) + " WHERE type='ponum'", conn);
                cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                ponumber = 0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            // LK 07/01/2011 <<D0050>>
            return ponumber.ToString().PadLeft(5, '0');
        }

        public int GetPosOnHold()
        {
            var lcSQL = "SELECT count(po_id) FROM " +
                        "potransactions (NOLOCK) " +
                        "WHERE status in ('HOLD') AND deleted = 0 AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                        "GROUP BY po_id ";

            var count_po_id = 0;

            SqlDataReader rdr = null;

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand(lcSQL, conn);

            try
            {
                conn.Open();
                count_po_id = Convert.ToInt32(cmd.ExecuteScalar());
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                count_po_id = 0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            // LK 14/01/2011 <<D0060>>
            return count_po_id;
        }

        public decimal GetSumApprovedByYear(int? budgetId, string dateStart)
        {

            decimal decReturn;

            var liOffset = -1;

            var lcWhereMonth = "";
            var lcWhereYear = "";

            var lcDateRange = " and dateposted_d between @Datetime AND DATEADD(year,1,@Datetime) ";

            var lcSql = "select sum(quantityordered_n * orderPrice_n) " +
                        " from potransactions (Nolock) " +
                        " WHERE 1=1 AND deleted = 0 AND ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                        lcDateRange +
                        " AND DeptCode_Id = " + budgetId +
                        " AND Status in ('SENT','APRVD','HOLD','SUSPD') ";

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand(lcSql, conn);

            try
            {

                cmd.Parameters.Add(new SqlParameter { ParameterName = "@Datetime", Value = dateStart });

                conn.Open();
                decReturn = Convert.ToDecimal(cmd.ExecuteScalar());
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                decReturn = (decimal)0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return decReturn;

        }

        public decimal GetSumApprovedByMonth(int monthPar, int? budgetId, int? period, DateTime? startdate)
        {

            decimal decReturn;

            var liOffset = -1;

            var monthOffset = period;

            var ldDateRange = " AND dateposted_d >= dateadd(month, " + (period - 1) + ", @Startdate) " +
                " AND dateposted_d< dateadd(month," + period + ", @Startdate)";

            var lcSql = "SELECT sum(quantityordered_n * orderPrice_n) " +
                        " FROM potransactions (Nolock) " +
                        " WHERE 1=1 AND deleted = 0 ([POAllocationOrder_N] < 1 OR [POAllocationOrder_N] is null) " +
                        ldDateRange +
                        " AND DeptCode_Id = " + budgetId +
                        " AND Status in ('SENT','APRVD','HOLD','SUSPD') ";

            var conn = ConnectionHelper.GetConnection();
            var cmd = new SqlCommand(lcSql, conn);

            try
            {
                var myParam = new SqlParameter();
                myParam.ParameterName = "@Startdate";
                myParam.SqlDbType = SqlDbType.DateTime;
                myParam.Value = startdate;
                cmd.Parameters.Add(myParam);

                conn.Open();
                decReturn = Convert.ToDecimal(cmd.ExecuteScalar());
            }

            catch (Exception ex)
            {
                EasyPoLog.LogError(MethodBase.GetCurrentMethod().Name, ex);
                decReturn = (decimal)0;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }

            return decReturn;

        }

        # endregion

        # region Properties

        public string Id { get; set; }
        public int Po_Id { get; set; }
        public string PoTranLine_C { get; set; }

        public string Description { get; set; }

        public string ReasonForOrder { get; set; }

        public string NomCode { get; set; }

        public string NomDesc { get; set; }

        public string SupplierCode { get; private set; }

        public double UnitPrice { get; set; }
        public double InvoicePrice { get; set; }

        public int Quantity { get; set; }
        public int QuantityReceived { get; set; }

        public double LineValue { get; set; }

        public string Notes { get; private set; }

        public string DeliveryNotes { get; set; }
        public DateTime DatePosted { get; set; }
        public DateTime DateTransaction { get; set; }
        public string PackSize { get; set; }

        public string WhyOrder { get; set; }

        public string Status { get; set; }

        public string Username { get; set; }

        # endregion

        # region Interfaces

        string IPurchase.Id
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IPurchase.Description
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IPurchase.ReasonForOrder
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IPurchase.NomCode
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        string IPurchase.NomDesc
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        double IPurchase.UnitPrice
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        int IPurchase.Quantity
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        int IPurchase.GetTotal()
        {
            throw new NotImplementedException();
        }

        string IPurchase.GetPoNumber(string currentPoNumber, int direction, string supplierCode)
        {
            throw new NotImplementedException();
        }

        List<Purchase> IPurchase.GetPurchaseOrder(string currentPoNumber)
        {
            throw new NotImplementedException();
        }

        List<string> IPurchase.GetListPoNumber(string status, int deptid)
        {
            throw new NotImplementedException();
        }

        string IPurchase.AddNewPoNumberRecord(string currentPoNumber, string selectedSupplier)
        {
            throw new NotImplementedException();
        }

        decimal IPurchase.CommitedThisMonthToDate()
        {
            throw new NotImplementedException();
        }

        # endregion
    }
}
